/**
 * anis.darwich
 */

package com;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

public class XBeeTest extends SerialComm {
	
	private final static Logger log = Logger.getLogger(XBeeTest.class);

	private final int delay = 0;

	
	private XBeeTest(String[] args) throws Exception {
		super();
		this.openSerialPort("COM7", 9600);
		this.run();
	}
	
	public static void main(String[] args) throws Exception {
		PropertyConfigurator.configure("log4j.properties");
		new XBeeTest(args);
	}
	
	protected Object getLock() {
		return this;
	}
	
	public void run() {
		MotionCommand rover_command = new MotionCommand( 2, 2); 
		try {	
			while (true) {
				this.sendCommand(rover_command.toSend());
				synchronized(this.getLock()) {				
					this.getLock().wait(TIMEOUT);
					log.debug(">>> Received " + this.getLastResponse());
					System.out.print(">>> Received " + this.getLastResponse()+ "\n");
				}
				Thread.sleep(delay);
			}
		} catch (Throwable th) {
			th.printStackTrace();
		}
	}
}
